package lanou.giftsay_01.main.categorymain;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import lanou.giftsay_01.R;
import lanou.giftsay_01.adapter.SelectGiftRvAdapter;
import lanou.giftsay_01.bean.SelectGiftAllBean;
import lanou.giftsay_01.tools.BaseActivity;
import lanou.giftsay_01.tools.NetTool;
import lanou.giftsay_01.tools.URLValues;

/**
 * Created by dllo on 16/8/26.
 */
public class GiftListActivity extends BaseActivity{

    private String id;
    private String name;
    private RecyclerView giftListRv;
    private TextView glTv;
    private SelectGiftRvAdapter glRvAdapter;
    private ImageView imageView;

    @Override
    protected int setLayout() {
        return R.layout.activity_giftlist;

    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        name = intent.getStringExtra("name");
        giftListRv = (RecyclerView) findViewById(R.id.giftlist_rv);
        GridLayoutManager manager = new GridLayoutManager(this , 2);
        giftListRv.setLayoutManager(manager);
        glTv = (TextView) findViewById(R.id.giftlist_title);
        imageView = (ImageView) findViewById(R.id.giftlist_iv);

    }

    @Override
    protected void initDate() {
         glTv.setText(name);
        glRvAdapter = new SelectGiftRvAdapter(this);
        NetTool netTool = new NetTool();
        netTool.getNetData(URLValues.PRODUCT_ALL + id + URLValues.PRODUCT_ALL1, SelectGiftAllBean.class, new NetTool.NetListener<SelectGiftAllBean>() {
            @Override
            public void onSuccess(SelectGiftAllBean selectGiftAllBean) {
                glRvAdapter.setSelectGiftAllBean(selectGiftAllBean);
                giftListRv.setAdapter(glRvAdapter);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
